<template>
  <div class="theme-picker">
    <el-dropdown trigger="click" @command="handleThemeChange">
      <div class="theme-picker-trigger">
        <i class="el-icon-brush"></i>
        <span>主题</span>
        <i class="el-icon-arrow-down el-icon--right"></i>
      </div>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="default">
          <div class="theme-item">
            <div class="theme-color default-theme"></div>
            <span>默认主题</span>
          </div>
        </el-dropdown-item>
        <el-dropdown-item command="blue">
          <div class="theme-item">
            <div class="theme-color blue-theme"></div>
            <span>蓝色主题</span>
          </div>
        </el-dropdown-item>
        <el-dropdown-item command="green">
          <div class="theme-item">
            <div class="theme-color green-theme"></div>
            <span>绿色主题</span>
          </div>
        </el-dropdown-item>
        <el-dropdown-item command="dark">
          <div class="theme-item">
            <div class="theme-color dark-theme"></div>
            <span>深色主题</span>
          </div>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import themeManager from '@/utils/theme'

export default {
  name: 'ThemePicker',
  data() {
    return {
      currentTheme: 'default'
    }
  },
  mounted() {
    // 从主题管理器获取当前主题
    this.currentTheme = themeManager.getCurrentTheme()
  },
  methods: {
    handleThemeChange(theme) {
      this.currentTheme = theme
      themeManager.setTheme(theme)
      this.$message.success(`已切换到${this.getThemeName(theme)}`)
    },
    getThemeName(theme) {
      const themeConfig = themeManager.getThemeConfig(theme)
      return themeConfig.name
    }
  }
}
</script>

<style lang="scss" scoped>
.theme-picker {
  display: inline-block;
  
  .theme-picker-trigger {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background-color 0.3s;
    
    &:hover {
      background-color: rgba(0, 0, 0, 0.1);
    }
    
    i {
      margin-right: 4px;
    }
  }
  
  .theme-item {
    display: flex;
    align-items: center;
    
    .theme-color {
      width: 16px;
      height: 16px;
      border-radius: 50%;
      margin-right: 8px;
      border: 1px solid #ddd;
    }
    
    .default-theme {
      background: linear-gradient(45deg, #1890ff, #409EFF);
    }
    
    .blue-theme {
      background: linear-gradient(45deg, #1890ff, #52c41a);
    }
    
    .green-theme {
      background: linear-gradient(45deg, #67C23A, #85ce61);
    }
    
    .dark-theme {
      background: linear-gradient(45deg, #1a1a1a, #2d2d2d);
    }
  }
}
</style>
